package cn.hznc.controller.toolAnalyze;

import cn.hznc.controller.service.toolAnalyze.ToolDemandForecastReportService;
import cn.hznc.domain.request.toolAnalyze.AssemblyRetrievalReq;
import cn.hznc.domain.request.toolAnalyze.ToolDemandForecastReportReq;
import cn.hznc.domain.request.toolforecast.ExportToolDemandForecastReportReq;
import cn.hznc.domain.response.ResponseBody;
import cn.hznc.exception.ToolScheduleException;
import cn.hznc.vo.OrderForecastReportExport;
import cn.hznc.vo.ToolUsageReportExport;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

@RestController
@CrossOrigin(origins = "*", maxAge = 3600)
@RequestMapping("/ToolDemandForecastReport")
@Slf4j
public class ToolDemandForecastReportController {
    @Resource
    private ToolDemandForecastReportService toolDemandForecastReportService;

    @RequestMapping(value = "/queryToolDemandForecastReport", method = RequestMethod.POST)
    public ResponseBody queryAssemblyRetrieval(@RequestBody AssemblyRetrievalReq assemblyRetrievalReq) throws ToolScheduleException {
        return ResponseBody.success(toolDemandForecastReportService.queryToolDemandForecastReport(assemblyRetrievalReq));
    }

    /**
     * 导出需求预测模版
     *
     * @return
     */
    @RequestMapping(value = "/exportToolDemandForecastReport", method = RequestMethod.POST)
    public void exportToolDemandForecastReport(HttpServletResponse response, @RequestBody OrderForecastReportExport orderForecastReportExport) {
        try {
            toolDemandForecastReportService.exportToolDemandForecastReport(response, orderForecastReportExport);
        } catch (ToolScheduleException e) {
            log.error(e.getCode(), e.getMessage());
        }
    }

    /**
     * 导出需求预测模版
     *
     * @return
     */
    @RequestMapping(value = "/exportToolUsageReport", method = RequestMethod.POST)
    public void exportToolUsageReport(HttpServletResponse response, @RequestBody ToolUsageReportExport toolUsageReportExport) {
        try {
            toolDemandForecastReportService.exportToolUsageReport(response , toolUsageReportExport);
        } catch (ToolScheduleException e) {
            log.error(e.getCode(), e.getMessage());
        }
    }
}
